// test/unit/SearchTest.php
<?php

require_once dirname(__FILE__).'/../bootstrap/unit.php';

$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'test', true);
new sfDatabaseManager($configuration);

$t = new lime_test(1, new lime_output_color());
$t->comment('->getForLuceneQuery()');
$data = BaseNotePeer::doSelect(new Criteria());
$t->comment('number of notes selected = '.count($data));
$c = 0;

foreach($data as $datum) {
	$c++;
     $t->comment('note ('.$c.'/'.count($data).') id:'.$datum->getId());
      $datum->updateLuceneIndex();
}

$data = BaseGroupPeer::doSelect(new Criteria());
$t->comment('number of groups selected = '.count($data));

$c = 0;
foreach($data as $datum) {
	$c++;
     $t->comment('group ('.$c.'/'.count($data).') id:'.$datum->getId());
      $datum->updateLuceneIndex();
}

$data = BaseUserPeer::doSelect(new Criteria());
$t->comment('number of users selected = '.count($data));

$c = 0;
foreach($data as $datum) {
	$c++;
     $t->comment('user ('.$c.'/'.count($data).') id:'.$datum->getId());
      $datum->updateLuceneIndex();
}

$data = BaseCoursePeer::doSelect(new Criteria());
$t->comment('number of courses selected = '.count($data));

$c = 0;
foreach($data as $datum) {
	$c++;
     $t->comment('course ('.$c.'/'.count($data).') id:'.$datum->getId());
      $datum->updateLuceneIndex();
}

$data = BaseFilePeer::doSelect(new Criteria());
$t->comment('number of files selected = '.count($data));

$c = 0;
foreach($data as $datum) {
	$c++;
     $t->comment('file ('.$c.'/'.count($data).') id:'.$datum->getId());
      $datum->updateLuceneIndex();
}

$data = BaseBookPeer::doSelect(new Criteria());
$t->comment('number of books selected = '.count($data));

$c = 0;
foreach($data as $datum) {
	$c++;
     $t->comment('book ('.$c.'/'.count($data).') id:'.$datum->getId());
      $datum->updateLuceneIndex();
}

$data = BaseAnnotationPeer::doSelect(new Criteria());
$t->comment('number of annotations selected = '.count($data));

$c = 0;
foreach($data as $datum) {
	$c++;
     $t->comment('annotion ('.$c.'/'.count($data).') id:'.$datum->getId());
      $datum->updateLuceneIndex();
}

$data = Search::getForLuceneQuery(Search::NOTE,'study');
$t->comment('search for study - number of notes returned = '.count($data));
foreach($data as $datum) {
        $t->comment('note '.$datum->pk.' '.$datum->topic);
}
$data = Search::getForLuceneQuery(Search::COURSE,'a');
$t->comment('search for a - number of courses returned = '.count($data));
foreach($data as $datum) {
        $t->comment('course '.$datum->pk.' '.$datum->name);
}
$data = Search::getForLuceneQuery(Search::GROUP,'a');
$t->comment('search for a - number of groups returned = '.count($data));
foreach($data as $datum) {
        $t->comment('group '.$datum->pk.' '.$datum->name);
}
$data = Search::getForLuceneQuery(Search::USER,'a');
$t->comment('search for a - number of users returned = '.count($data));
foreach($data as $datum) {
        $t->comment('user '.$datum->pk.' '.$datum->username);
}
$data = Search::getForLuceneQuery(Search::FILE,'a');
$t->comment('search for a - number of files returned = '.count($data));
foreach($data as $datum) {
        $t->comment('file '.$datum->pk.' '.$datum->name);
}
$data = Search::getForLuceneQuery(Search::BOOK,'love');
$t->comment('search for love - number of books returned = '.count($data));
foreach($data as $datum) {
        $t->comment('book '.$datum->pk.' '.$datum->title);
}
$data = Search::getForLuceneQuery(Search::ANNOTATION,'world');
$t->comment('search for world - number of annotations returned = '.count($data));
foreach($data as $datum) {
        $t->comment('annotation '.$datum->pk.' '.$datum->text);
}
$t->pass('This test always passes.');
